﻿using System;
using System.Threading;
using System.Threading.Tasks;
using Iot.RealTimeData.RealTimeData;
using Iot.Shared.Model;
using Mediator;
using Microsoft.Extensions.Logging;

namespace Iot.RealTimeData.RealTimeDataEvent;

public sealed class RealTimeDataEventEnum(
    IRealTimeData<Enum?, IOnEnumValue> data,
    ILogger<RealTimeDataEventEnum> logger)
    : INotificationHandler<EnumBusModel>
{
    public ValueTask Handle(EnumBusModel notification, CancellationToken cancellationToken)
    {
        // 调用_data的SetValue方法，将notification.Path、notification.Value、notification.Timestamp作为参数传入
        logger.LogTrace("函数:{函数},开始处理通知{notification}.", nameof(Handle), notification);
        data.SetValue(notification.Path, notification.Value, notification.TimeStamp);
        logger.LogTrace("函数:{函数},通知{notification}设置值成功.", nameof(Handle), notification);
        return ValueTask.CompletedTask;
    }
}